$(function() {
	admin.homemakingBase.init();
});
Namespace('admin.homemakingBase', {
	init : function() {
		easyui.util.initDatagrid('#datagrid', {
			onDblClickRow : function() {
				var row = $('#datagrid').datagrid('getSelected');
				admin.homemakingBase.detail(row.id);
			}
		});
	},
	query : function() {
		if (!$('#query-form').form('validate'))
			return;
		var data = $('#query-form').form('jsonObject');
		$('#datagrid').datagrid('load', data);
	},
	detail:function(id) {
		if (id != null) {
			top.addTab(id,'详情', contextPath+'/homemaking/base/detail?id=' + id);
		}
	},
	orderList: function (id,nick) {
		if (id != null) {
			top.addTab(id,nick+'的预约', contextPath+'/homemaking/order/list/' + id);
		}
	},
	timeList: function (id,nick) {
		if (id != null) {
			top.addTab("time"+id,nick+'的休息', contextPath+'/homemaking/time/list/' + id);
		}
	},
	setIsShow: function (id,isShow) {
		var tip = "确定屏蔽吗";
		if (isShow) {
			tip = "确定解除屏蔽吗";
		}
		$.messager.confirm('信息提示', tip, function (success) {
			if (!success) {
				return;
			}
            var url = contextPath + '/community/base/show';
			if (!isShow) {
				url = contextPath + '/community/base/hide';
			}
			$('#datagrid').datagrid('loading');
			$.post(url, {'id': id}, function (result) {
				$('#datagrid').datagrid('loaded');
				if (result.code == 1) {
					top.showInfo('操作成功');
					var pageopt = $('#datagrid').datagrid('getPager').data("pagination").options;
					console.log(pageopt.pageNumber);
                    admin.communityBase.query();
				} else {
					top.showInfo(result.msg);
				}
			});

		});
	},
	setAuditStatus: function (id,auditStatus) {
		$.messager.confirm('信息提示', "确定要操作吗", function (success) {
			if (!success) {
				return;
			}
			var url = contextPath + '/homemaking/base/auditStatus';
			$.postJson(url, {'id': id,'auditStatus':auditStatus}, function (result) {
				$('#datagrid').datagrid('loaded');
				if (result.code == 1) {
					top.showInfo('操作成功');
					admin.homemakingBase.query();
				} else {
					top.showInfo(result.msg);
				}
			});
		});
	},
	setStatus: function (id,status) {
		var msg = "确定要暂停接单吗";
		if (status == 1) {
			msg = "确定要开启接单吗";
		}
		$.messager.confirm('信息提示', msg, function (success) {
			if (!success) {
				return;
			}
			var url = contextPath + '/homemaking/base/status';
			$.postJson(url, {'id': id,'status':status}, function (result) {
				$('#datagrid').datagrid('loaded');
				if (result.code == 1) {
					top.showInfo('操作成功');
					admin.homemakingBase.query();
				} else {
					top.showInfo(result.msg);
				}
			});
		});
	}
});